#include "Cat.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdio>

Cat::Cat()
{
          string COLOR;

}//end Data Members
Cat::~Cat()
{
}
Cat::Cat(string name, string sex, string color)
{
          if(sex!= "male" && sex!= "female") throw AppError("invalid sex", "Cat::Cat");
          if(dna!= "cat") throw AppError("invalid dna", "Cat::Cat");
          Pet::name = name;
          Pet::sex = sex;
          Pet::dna = "Cat";
          COLOR = color;

}//end Constructor

void Cat::Perform (string cmd, ostream& fout ) throw (AppError)
{

          if (cmd == "name?")
               fout << "My name is: " << Pet::MyNameIs() << endl;
          else if (cmd == "color?")
               fout << "My color is: " << COLOR << endl;
          else if (cmd == "species?")
               fout << "My species is: " << Pet::MySpeciesIs() << endl;
          else if (cmd == "sex?")
               fout << "My sex is: " << Pet::MySexIs() << endl;
          else if (cmd == "speak!")
               fout << "My cry is: " << Cat::Cry() << endl;
          else throw AppError("Invalid Command", "Cat::Perform");


}//end Perform

string Cat::MyColorIs ()
{
       return COLOR;
}//end MyColorIs

string Cat::Cry ()
{
     return "Meow";
}//end Cry

void Cat::Extract( ifstream& fin ) throw (TokenError)
{
     string opentkn, closetkn;
     fin >> opentkn;
     if(opentkn!= "Cat{")
     {
          throw TokenError("Invalid Open Token!", "Cat::Extract(1)");
     }
     Get(fin);
     fin >> closetkn;
     if(closetkn!= "}Cat")
     {
          throw TokenError("Invalid Close Token!", "Cat::Extract(2)");
     }
}

void Cat::Insert( ostream& fout )
{
     fout << "Cat{ " ;
     Put(fout);
     fout << " }Cat";
}
//void Cat::Get(&ifstream fin) throw TokenError()
void Cat::Get( ifstream& fin) throw(TokenError)

{
   string reader;
   fin  >> reader;
   if( reader != "name:" )
	   throw TokenError("Invalid field label, name: expected", "Cat::Get(1)");
   fin  >> Pet::name;
   fin  >> reader;
   if( reader != "dna:" )
	   throw TokenError("Invalid field label, dna: expected", "Cat::Get(2)");
   fin  >> Pet::dna;
   fin  >> reader;
   if( reader != "sex:" )
	   throw TokenError("Invalid field label, sex: expected", "Cat::Get(3)");
   fin  >> Pet::sex;
   fin  >> reader;
   if( reader != "color:" )
	   throw TokenError("Invalid field label, color: expected", "Cat::Get(4)");
   fin  >> COLOR;

}

//void Cat::Put(&ofstream fout) throw TokenError()
void Cat::Put ( ostream& fout)
	 {
           fout << " name: "   << Pet::name
                << " dna: "    << Pet::dna
                << " sex: "    << Pet::sex
                << " color: "  << COLOR;
     }
